/*
 * \brief  Dummy functions to make the damn thing link
 * \author Norman Feske
 * \date   2006-04-07
 */

/*
 * Copyright (C) 2006-2009 Norman Feske
 * Genode Labs, Feske & Helmuth Systementwicklung GbR
 *
 * This file is part of the Genode OS framework, which is distributed
 * under the terms of the GNU General Public License version 2.
 */

#include <base/printf.h>
#include <base/stdint.h>
#include <base/sleep.h>
#include <util/string.h>

using namespace Genode;


extern "C" void __cxa_pure_virtual()
{
	PWRN("cxa pure virtual function called, return addr is %p",
	     __builtin_return_address(0));
}


extern "C" void __pure_virtual()
{
	PWRN("pure virtual function called");
}


extern "C" __attribute__((weak))
int __cxa_atexit(void (*func)(void*), void *arg, void *dso_handle)
{
	return -1;
}


/***************************
 ** Support for libsupc++ **
 ***************************/

extern "C" void *abort(void)
{
	PDBG("abort called");
	sleep_forever();
	return 0;
}


extern "C" void *fputc(void) {
	PWRN("fputc - not yet implemented");
	return 0;
}


extern "C" void *fputs(const char *s, void *) {
	PWRN("fputs: \"%s\"", s);
	return 0;
}


extern "C" void *fwrite(void) {
	PWRN("fwrite - not yet implemented");
	return 0;
}


extern "C" __attribute__((weak))
void *memcpy(void *dst, void *src, size_t n)
{
//	PDBG("dst=%p, src=%p, n=%d", dst, src, n);
	return Genode::memcpy(dst, src, n);
}


extern "C" __attribute__((weak))
void *memmove(void *dst, void *src, size_t n)
{
//	PDBG("dst=%p, src=%p, n=%d", dst, src, n);
	return Genode::memmove(dst, src, n);
}


extern "C" void *memset(void *s, int c, size_t n)
{
//	PDBG("s=%p, c=%d, n=%d", s, c, n);
	return Genode::memset(s, c, n);
}


extern "C" void *realloc(void) { 
	PWRN("realloc - not yet implemented");
	return 0;
}


extern "C" void *stderr(void) { 
	PWRN("stderr - not yet implemented");
	return 0;
}


extern "C" void *strcat(void) { 
	PWRN("strcat - not yet implemented");
	return 0;
}


extern "C" void *strcpy(void) { 
	PWRN("strcpy - not yet implemented");
	return 0;
}


extern "C" size_t strlen(const char *s)
{
	return Genode::strlen(s);
}


/**********************************
 ** Support for stack protection **
 **********************************/

extern "C" void __stack_chk_fail_local (void)
{
	PERR("Violated stack boundary");
}
